package com.ruoyi.web.controller.prt;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.prt.domain.PrtPriceMode;
import com.ruoyi.prt.service.IPrtPriceModeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 打印价格模板Controller
 *
 * @author xiaobo Yan
 * @date 2021-03-31
 */
@RestController
@RequestMapping("/prt/pricemode")
public class PrtPriceModeController extends BaseController
{
    @Autowired
    private IPrtPriceModeService prtPriceModeService;

    /**
     * 查询打印价格模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:pricemode:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrtPriceMode prtPriceMode)
    {
        startPage();
        List<PrtPriceMode> list = prtPriceModeService.selectPrtPriceModeList(prtPriceMode);
        return getDataTable(list);
    }

    /**
     * 导出打印价格模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:pricemode:export')")
    @Log(title = "打印价格模板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PrtPriceMode prtPriceMode)
    {
        List<PrtPriceMode> list = prtPriceModeService.selectPrtPriceModeList(prtPriceMode);
        ExcelUtil<PrtPriceMode> util = new ExcelUtil<PrtPriceMode>(PrtPriceMode.class);
        return util.exportExcel(list, "pricemode");
    }

    /**
     * 获取打印价格模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pricemode:query')")
    @GetMapping(value = "/{priceModeId}")
    public AjaxResult getInfo(@PathVariable("priceModeId") String priceModeId)
    {
        return AjaxResult.success(prtPriceModeService.selectPrtPriceModeById(priceModeId));
    }

    /**
     * 新增打印价格模板
     */
    @PreAuthorize("@ss.hasPermi('system:pricemode:add')")
    @Log(title = "打印价格模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrtPriceMode prtPriceMode)
    {
        return toAjax(prtPriceModeService.insertPrtPriceMode(prtPriceMode));
    }

    /**
     * 修改打印价格模板
     */
    @PreAuthorize("@ss.hasPermi('system:pricemode:edit')")
    @Log(title = "打印价格模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrtPriceMode prtPriceMode)
    {
        return toAjax(prtPriceModeService.updatePrtPriceMode(prtPriceMode));
    }

    /**
     * 删除打印价格模板
     */
    @PreAuthorize("@ss.hasPermi('system:pricemode:remove')")
    @Log(title = "打印价格模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{priceModeIds}")
    public AjaxResult remove(@PathVariable String[] priceModeIds)
    {
        return toAjax(prtPriceModeService.deletePrtPriceModeByIds(priceModeIds));
    }
}
